﻿@using Fluxor.Blazor.Web.Components;
@using Microsoft.AspNetCore.Html;
@using Microsoft.IdentityModel.Tokens;
@using SimpleIdServer.IdServer.Website.Resources;
@using SimpleIdServer.IdServer.Website.Stores.ClientStore;
@inherits FluxorComponent
@inject Radzen.DialogService dialogService
@inject NotificationService notificationService
@inject IState<AddClientState> addClientState
@inject IDispatcher dispatcher

<RadzenSteps>
    <Steps>
        <RadzenStepsItem Text="@Global.ApplicationType">
            <!-- Choose a template -->
            <div>
                <RadzenLabel Text="@Global.ChooseTemplate" />
                <RadzenDropDown @bind-Value=@SelectedClientType 
                    TValue="ClientTemplateTypes"
                    Data="@ClientTemplates"
                    Change=@(args => SelectClientType(args))
                    TextProperty="Name" ValueProperty="Type"></RadzenDropDown>
            </div>
            <!-- Client types -->
            <div class="row gy-4 mt-1">
                @foreach (var appType in ApplicationTypes)
                {
                    <div class="col-md-6">
                        <RadzenCard @onclick="() => SelectApplication(appType)" class="@(SelectedApplicationType != null && SelectedApplicationType.Name == appType.Name ? "selected selectable" : "selectable")">
                            <div class="row">
                                <div class="col-md-3">
                                    <RadzenImage Path="@appType.PictureUrl" Style="width: 60px" />
                                </div>
                                <div class="col">
                                    <h5>@appType.Name</h5>
                                    <p class="text-muted">@(new MarkupString(appType.ShortDescription))</p>
                                </div>
                            </div>
                        </RadzenCard>
                    </div>
                }
            </div>

            <hr />

            @if (SelectedApplicationType != null)
            {
                <h5><RadzenIcon Icon="info" /> @SelectedApplicationType.Name</h5>
                <p class="text-muted">@(new MarkupString(SelectedApplicationType.Description))</p>
            }
        </RadzenStepsItem>
        <RadzenStepsItem Text="Properties" Disabled="@(SelectedApplicationType == null)">
            @if(SelectedApplicationType != null)
            {
                switch(SelectedApplicationType.Type)
                {
                    // SPA application
                    case ClientTypes.SPA:
                        <RadzenTemplateForm Submit=@AddSpaApplication TItem="SpaApplication" Data=@spaApplication>
                            @if(!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@spaApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@spaApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.RedirectionUrls</RadzenText>
                                <RadzenTextBox Name="RedirectionUris" @bind-Value="@spaApplication.RedirectionUris" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.RedirectionUrlsDescription))
                                </p>
                                <RadzenRequiredValidator Component="RedirectionUris" Text="@Global.AtLeastOneRedirectionUrl"></RadzenRequiredValidator>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Machine application
                    case ClientTypes.MACHINE:
                        <RadzenTemplateForm Submit=@AddMachineApplication TItem="MachineApplication" Data=@machineApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@machineApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@machineApplication.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@machineApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Website application.
                    case ClientTypes.WEBSITE:
                        <RadzenTemplateForm Submit=@AddWebsiteApplication TItem="WebsiteApplication" Data=@websiteApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }

                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@websiteApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@websiteApplication.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@websiteApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.RedirectionUrls</RadzenText>
                                <RadzenTextBox Name="RedirectionUris" @bind-Value="@websiteApplication.RedirectionUris" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.RedirectionUrlsDescription))
                                </p>
                                <RadzenRequiredValidator Component="RedirectionUris" Text="@Global.AtLeastOneRedirectionUrl"></RadzenRequiredValidator>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Mobile application.
                    case ClientTypes.MOBILE:
                        <RadzenTemplateForm Submit=@AddMobileApplication TItem="MobileApplication" Data=@mobileApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@mobileApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@mobileApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.RedirectionUrls</RadzenText>
                                <RadzenTextBox Name="RedirectionUris" @bind-Value="@mobileApplication.RedirectionUris" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.RedirectionUrlsDescription))
                                </p>
                                <RadzenRequiredValidator Component="RedirectionUris" Text="@Global.AtLeastOneRedirectionUrl"></RadzenRequiredValidator>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Ws-Federation
                    case ClientTypes.WSFEDERATION:
                        <RadzenTemplateForm Submit=@AddWsFederationApplication TItem="WsFederationApplication" Data=@wsFederationApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@wsFederationApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@wsFederationApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Device
                    case ClientTypes.DEVICE:
                        <RadzenTemplateForm Submit="@AddDeviceApplication" TItem="DeviceApplication" Data="@deviceApplication">
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }

                            <!-- Client Identifier -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@deviceApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <!-- Client Name -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@deviceApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <!-- Client Secret -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@deviceApplication.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretIsRequired"></RadzenRequiredValidator>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;                        
                    // Device
                    case ClientTypes.SAML:
                        <RadzenTemplateForm Submit="@AddSamlSpApplication" TItem="SamlSpApplication" Data="@samlSpApplication">
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }

                            <!-- Client Identifier -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@samlSpApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <!-- Client Name -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@samlSpApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <!-- Metadata Url -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.MetadataUrl</RadzenText>
                                <RadzenTextBox Name="MetadataUrl" @bind-Value="@samlSpApplication.MetadataUrl" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="MetadataUrl" Text="@Global.MetadataUrlRequired"></RadzenRequiredValidator>
                            </div>
                            <!-- Use Artifact -->
                            <div>
                                <RadzenCheckBox Name="UseAcs" @bind-Value="@samlSpApplication.UseAcs"></RadzenCheckBox>
                                <RadzenLabel Text="@Global.UseArtifact" Component="UseAcs" Style="margin-left: 8px; vertical-align: middle;" />
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;    
                    // Highly secured web application.
                    case ClientTypes.HIGHLYSECUREDWEBSITE:
                        <RadzenTemplateForm Submit=@AddHighlySecuredWebsiteApplication TItem="HighlySecuredWebApplication" Data=@highlySecuredWebsiteApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@highlySecuredWebsiteApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@highlySecuredWebsiteApplication.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@highlySecuredWebsiteApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.RedirectionUrls</RadzenText>
                                <RadzenTextBox Name="RedirectionUris" @bind-Value="@highlySecuredWebsiteApplication.RedirectionUris" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.RedirectionUrlsDescription))
                                </p>
                                <RadzenRequiredValidator Component="RedirectionUris" Text="@Global.AtLeastOneRedirectionUrl"></RadzenRequiredValidator>
                            </div>
                            <!-- Choose proof of possession -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.ProofOfPossession</RadzenText>
                                <RadzenDropDown TValue=string @bind-Value=@highlySecuredWebsiteApplication.ProofOfPossession Data=@ProofOfPossessions TextProperty="Description" ValueProperty="Name" />
                                <p class="text-muted">
                                    @((MarkupString)(@Global.SelectProofOfPossessionHelper))
                                </p>
                            </div>
                            @if (highlySecuredWebsiteApplication.ProofOfPossession == MtlsName)
                            {
                                <RadzenAlert AlertStyle="AlertStyle.Info" ShowIcon="false" Variant="Variant.Flat" AllowClose="false" Shade="Shade.Lighter">
                                    @((MarkupString)(@Global.SelectMtlsProofOfPossessionHelper))
                                </RadzenAlert>
                                <div>
                                    <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.SubjectName</RadzenText>
                                    <RadzenTextBox Name="SubjectName" @bind-Value="@highlySecuredWebsiteApplication.SubjectName" Class="w-100"></RadzenTextBox>
                                    <p class="text-muted">
                                        @((MarkupString)(@Global.MtlsProofOfPossessionSubjectNameHelper))
                                    </p>
                                </div>
                            }
                            else if (highlySecuredWebsiteApplication.ProofOfPossession == DpopName)
                            {
                                <RadzenAlert AlertStyle="AlertStyle.Info" ShowIcon="false" Variant="Variant.Flat" AllowClose="false" Shade="Shade.Lighter">
                                    @((MarkupString)(@Global.SelectDpopProofOfPossessionHelper))
                                </RadzenAlert>
                            }

                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Highly secured web application with Grant Management support
                    case ClientTypes.GRANTMANAGEMENT:
                        <RadzenTemplateForm Submit=@AddHighlySecuredWebsiteApplicationWithGrantMgtSupport TItem="HighlySecuredWebApplicationWithGrantMgtSupport" Data=@highlySecuredWebApplicationWithGrantMgtSupport>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@highlySecuredWebApplicationWithGrantMgtSupport.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@highlySecuredWebApplicationWithGrantMgtSupport.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@highlySecuredWebApplicationWithGrantMgtSupport.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.RedirectionUrls</RadzenText>
                                <RadzenTextBox Name="RedirectionUris" @bind-Value="@highlySecuredWebApplicationWithGrantMgtSupport.RedirectionUris" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.RedirectionUrlsDescription))
                                </p>
                                <RadzenRequiredValidator Component="RedirectionUris" Text="@Global.AtLeastOneRedirectionUrl"></RadzenRequiredValidator>
                            </div>
                            <!-- Grant management -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.AuthorizationDataTypes</RadzenText>
                                <RadzenTextBox Name="AuthDataTypes" @bind-Value="@highlySecuredWebApplicationWithGrantMgtSupport.AuthDataTypes" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.AuthorizationDataTypesDescription))
                                </p>
                            </div>
                            <!-- Choose proof of possession -->
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.ProofOfPossession</RadzenText>
                                <RadzenDropDown TValue=string @bind-Value=@highlySecuredWebApplicationWithGrantMgtSupport.ProofOfPossession Data=@ProofOfPossessions TextProperty="Description" ValueProperty="Name" />
                                <p class="text-muted">
                                    @((MarkupString)(@Global.SelectProofOfPossessionHelper))
                                    </p>
                            </div>
                            @if (highlySecuredWebApplicationWithGrantMgtSupport.ProofOfPossession == MtlsName)
                            {
                                <RadzenAlert AlertStyle="AlertStyle.Info" ShowIcon="false" Variant="Variant.Flat" AllowClose="false" Shade="Shade.Lighter">
                                    @((MarkupString)(@Global.SelectMtlsProofOfPossessionHelper))
                                </RadzenAlert>
                                <div>
                                    <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.SubjectName</RadzenText>
                                    <RadzenTextBox Name="SubjectName" @bind-Value="@highlySecuredWebApplicationWithGrantMgtSupport.SubjectName" Class="w-100"></RadzenTextBox>
                                    <p class="text-muted">
                                        @((MarkupString)(@Global.MtlsProofOfPossessionSubjectNameHelper))
                                    </p>
                                </div>
                            }
                            else if (highlySecuredWebApplicationWithGrantMgtSupport.ProofOfPossession == DpopName)
                            {
                                <RadzenAlert AlertStyle="AlertStyle.Info" ShowIcon="false" Variant="Variant.Flat" AllowClose="false" Shade="Shade.Lighter">
                                    @((MarkupString)(@Global.SelectDpopProofOfPossessionHelper))
                                </RadzenAlert>
                            }

                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // External Device used for the authentication.
                    case ClientTypes.EXTERNAL:
                        <RadzenTemplateForm Submit=@AddExternalDeviceApplication TItem="ExternalDeviceApplication" Data=@externalDeviceApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@externalDeviceApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@externalDeviceApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.SubjectName</RadzenText>
                                <RadzenTextBox Name="SubjectName" @bind-Value="@externalDeviceApplication.SubjectName" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)(@Global.MtlsAuthenticationIsEnabled))
                                </p>
                                <RadzenRequiredValidator Component="SubjectName" Text="@Global.SubjectNameRequired"></RadzenRequiredValidator>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;
                    // Credential issuer
                    case ClientTypes.CREDENTIALISSUER:
                        <RadzenTemplateForm Submit=@AddCredentialIssuerApplication TItem="CredentialIssuerApplication" Data=@credentialIssuerApplication>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@credentialIssuerApplication.ClientIdentifier" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@credentialIssuerApplication.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@credentialIssuerApplication.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.RedirectionUrls</RadzenText>
                                <RadzenTextBox Name="RedirectionUris" @bind-Value="@credentialIssuerApplication.RedirectionUris" Class="w-100"></RadzenTextBox>
                                <p class="text-muted">
                                    @((MarkupString)Global.RedirectionUrlsDescription)
                                </p>
                                <RadzenRequiredValidator Component="RedirectionUris" Text="@Global.AtLeastOneRedirectionUrl"></RadzenRequiredValidator>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>
                        break;  
                    // Wallet
                    case ClientTypes.WALLET:
                        <RadzenTemplateForm Submit=@AddWallet TItem="Wallet" Data=@wallet>
                            @if (!addClientState.Value.IsAdding && !string.IsNullOrWhiteSpace(addClientState.Value.ErrorMessage))
                            {
                                <RadzenAlert AllowClose="false" AlertStyle="AlertStyle.Danger" ShowIcon="true" Variant="Variant.Flat" Shade="Shade.Lighter">@addClientState.Value.ErrorMessage</RadzenAlert>
                            }
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Identifier</RadzenText>
                                <RadzenTextBox Name="ClientIdentifier" @bind-Value="@wallet.ClientId" Class="w-100"></RadzenTextBox>
                                <RadzenRequiredValidator Component="ClientIdentifier" Text="@Global.IdentifierIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Secret</RadzenText>
                                <RadzenPassword Name="ClientSecret" @bind-Value="@wallet.ClientSecret" Class="w-100"></RadzenPassword>
                                <RadzenRequiredValidator Component="ClientSecret" Text="@Global.SecretIsRequired"></RadzenRequiredValidator>
                            </div>
                            <div>
                                <RadzenText TextStyle="TextStyle.Subtitle2" TagName="TagName.H3">@Global.Name</RadzenText>
                                <RadzenTextBox Name="ClientName" @bind-Value="@wallet.ClientName" Class="w-100"></RadzenTextBox>
                            </div>
                            <RadzenButton class="mt-1" Variant="Variant.Flat" ButtonType="ButtonType.Submit" ButtonStyle="ButtonStyle.Success" Text="@(addClientState.Value.IsAdding ? Global.Adding : Global.Save)" Disabled="@(addClientState.Value.IsAdding)" />
                        </RadzenTemplateForm>

                        break;
                }
            }
        </RadzenStepsItem>
    </Steps>
</RadzenSteps>

@code {
    static string DpopName = "DPoP";
    static string MtlsName = "MTLS";

    record ApplicationType
    {
        public string Name { get; set; } = null!;
        public string ShortDescription { get; set; } = null!;
        public string Description { get; set; } = null!;
        public ClientTypes Type { get; set; }
        public string PictureUrl { get; set; } = null!;
        public ClientTemplateTypes ClientTemplate { get; set; }
    }

    record SpaApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string RedirectionUris { get; set; } = null!;
    }

    record WebsiteApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string ClientSecret { get; set; } = null!;
        public string RedirectionUris { get; set; } = null!;
    }

    record HighlySecuredWebApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string ClientSecret { get; set; } = null!;
        public string RedirectionUris { get; set; } = null!;
        public string SubjectName { get; set; } = null!;
        public string ProofOfPossession { get; set; } = MtlsName;
    }

    record HighlySecuredWebApplicationWithGrantMgtSupport
    {        
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string ClientSecret { get; set; } = null!;
        public string RedirectionUris { get; set; } = null!;
        public string SubjectName { get; set; } = null!;
        public string ProofOfPossession { get; set; } = MtlsName;
        public string? AuthDataTypes { get; set; } = null;
    }

    record MachineApplication
    {
        public string ClientName { get; set;} = null!;
        public string ClientSecret { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
    }

    record MobileApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string RedirectionUris { get; set; } = null!;
    }

    record ExternalDeviceApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string SubjectName { get; set; } = null!;
    }

    record WsFederationApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
    }

    record SamlSpApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set; } = null!;
        public string MetadataUrl { get; set; } = null!;
        public bool UseAcs { get; set; } = false;
    }

    record DeviceApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set;} = null!;
        public string ClientSecret { get; set; } = null!;
    }

    record CredentialIssuerApplication
    {
        public string ClientName { get; set; } = null!;
        public string ClientIdentifier { get; set;} = null!;
        public string ClientSecret { get; set;} = null!;
        public string RedirectionUris { get; set; }
    }

    record Wallet
    {
        public string ClientId { get; set; }
        public string ClientSecret { get; set; }
        public string ClientName { get; set; }
    }

    record ProofOfPossession
    {
        public string Name { get; set; }
        public string Description { get; set; }
    }

    record ClientTemplate
    {
        public ClientTemplateTypes Type { get; set; }
        public string Name { get; set; }
    }

    SpaApplication spaApplication = new SpaApplication();
    MachineApplication machineApplication = new MachineApplication();
    WebsiteApplication websiteApplication = new WebsiteApplication();
    HighlySecuredWebApplication highlySecuredWebsiteApplication = new HighlySecuredWebApplication();
    HighlySecuredWebApplicationWithGrantMgtSupport highlySecuredWebApplicationWithGrantMgtSupport = new HighlySecuredWebApplicationWithGrantMgtSupport();
    MobileApplication mobileApplication = new MobileApplication();
    WsFederationApplication wsFederationApplication = new WsFederationApplication();
    ExternalDeviceApplication externalDeviceApplication = new ExternalDeviceApplication();
    DeviceApplication deviceApplication = new DeviceApplication();
    SamlSpApplication samlSpApplication = new SamlSpApplication();
    CredentialIssuerApplication credentialIssuerApplication = new CredentialIssuerApplication();
    Wallet wallet = new Wallet();
    ICollection<ProofOfPossession> ProofOfPossessions { get; set; } = new List<ProofOfPossession>
    {
        new ProofOfPossession { Name = DpopName, Description = "DPoP" },
        new ProofOfPossession { Name = MtlsName, Description = Global.Mtls }
    };
    enum ClientTemplateTypes
    {
        STANDARD = 0,
        FAPI = 1,
        CREDENTIALISSUER = 2
    }
    ClientTemplateTypes SelectedClientType = ClientTemplateTypes.STANDARD;

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        ApplicationTypes = AllApplicationTypes.Where(a => a.ClientTemplate == ClientTemplateTypes.STANDARD).ToList();
        SubscribeToAction<AddClientSuccessAction>(async (act) =>
        {
            dialogService.Close();
            notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Success, Summary = string.Format(Global.ClientAdded, act.ClientId) });

            await dialogService.OpenAsync<ViewAddedClientDialog>(string.Format(Global.ClientAdded, act.ClientId), new Dictionary<string, object>
            {
                { "Client", act }
            }, new DialogOptions
            {
                Width = "700px",
                Height = "512px",
                Resizable = true,
                Draggable = true
            });
            StateHasChanged();
        });
        dispatcher.Dispatch(new StartAddClientAction());
    }

    ICollection<ApplicationType> AllApplicationTypes { get; set; } = new List<ApplicationType>
    {
        new ApplicationType { Name = Global.UserBasedApp, ClientTemplate = ClientTemplateTypes.STANDARD, ShortDescription = Global.UserBasedAppShortDescription, Description = Global.UserBasedAppDescription, Type = ClientTypes.SPA, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/angular.png" },
        new ApplicationType { Name = Global.Machine, ClientTemplate = ClientTemplateTypes.STANDARD, ShortDescription = Global.MachineShortDescription, Description = Global.MachineDescription, Type = ClientTypes.MACHINE, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/MachineClient.png" },
        new ApplicationType { Name = Global.WebApp, ClientTemplate = ClientTemplateTypes.STANDARD, ShortDescription = Global.WebAppShortDescription, Description = Global.WebAppDescription, Type = ClientTypes.WEBSITE, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/WebsiteClient.png" },
        new ApplicationType { Name = Global.Mobile, ClientTemplate = ClientTemplateTypes.STANDARD, ShortDescription = Global.MobileShortDescription, Description = Global.MobileDescription, Type = ClientTypes.MOBILE, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/MobileClient.png" },
        new ApplicationType { Name = Global.WsRelyingParty, ClientTemplate = ClientTemplateTypes.STANDARD,  ShortDescription = Global.WsRelyingPartyShortDescription, Description = Global.WsRelyingPartyDescription, Type = ClientTypes.WSFEDERATION, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/WsFedClient.png" },
        new ApplicationType { Name = Global.SamlSp, ClientTemplate = ClientTemplateTypes.STANDARD, ShortDescription = Global.SamlSpShortDescription, Description = Global.SamlSpDescription, Type = ClientTypes.SAML, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/SAMLSP.png" },
        new ApplicationType { Name = Global.Device, ClientTemplate = ClientTemplateTypes.STANDARD,  ShortDescription = Global.DeviceShortDescription, Description = Global.DeviceDescription, Type = ClientTypes.DEVICE, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/DeviceClient.png" },
        new ApplicationType { Name = Global.HighlySecuredWebApp, ClientTemplate = ClientTemplateTypes.FAPI, ShortDescription = Global.HighlySecuredWebAppShortDescription, Description = Global.HighlySecuredWebAppDescription, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/WebsiteClient.png", Type = ClientTypes.HIGHLYSECUREDWEBSITE },
        new ApplicationType { Name = Global.GrantMgt, ClientTemplate = ClientTemplateTypes.FAPI, ShortDescription = Global.GrantMgtShortDescription, Description = Global.GrantMgtDescription, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/WebsiteClient.png", Type = ClientTypes.GRANTMANAGEMENT },
        new ApplicationType { Name = Global.ExternalDeviceAuth, ClientTemplate = ClientTemplateTypes.FAPI,  ShortDescription = Global.ExternalDeviceAuthShortDescription, Description = Global.ExternalDeviceDescription, Type = ClientTypes.EXTERNAL, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/ExternalDeviceClient.png" },
        new ApplicationType { Name = Global.CredentialIssuer, ClientTemplate = ClientTemplateTypes.CREDENTIALISSUER, ShortDescription = Global.CredentialIssuerShortDescription, Description = Global.CredentialIssuerDescription, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/CredentialIssuer.png", Type = ClientTypes.CREDENTIALISSUER },
        new ApplicationType { Name = Global.Wallet, ClientTemplate = ClientTemplateTypes.CREDENTIALISSUER, ShortDescription = Global.WalletShortDescription, Description = Global.WalletDescription, PictureUrl = "_content/SimpleIdServer.IdServer.Website/images/Wallet.png", Type = ClientTypes.WALLET }
    };

    ICollection<ClientTemplate> ClientTemplates { get; set; } = new List<ClientTemplate>
    {
        new ClientTemplate { Name = Global.Standard, Type = ClientTemplateTypes.STANDARD },
        new ClientTemplate { Name = "FAPI2.0", Type = ClientTemplateTypes.FAPI },
        new ClientTemplate { Name = Global.CredentialIssuer, Type = ClientTemplateTypes.CREDENTIALISSUER }
    };

    ApplicationType? SelectedApplicationType { get; set; } = null;

    ICollection<ApplicationType> ApplicationTypes { get; set; } = new List<ApplicationType>();

    void SelectClientType(object args)
    {
        ApplicationTypes = AllApplicationTypes.Where(a => a.ClientTemplate == (ClientTemplateTypes)args).ToList();
    }

    void SelectApplication(ApplicationType appType)
    {
        SelectedApplicationType = appType;
    }

    void AddSpaApplication(SpaApplication spaApplication)
    {
        dispatcher.Dispatch(new AddSpaClientAction { ClientId = spaApplication.ClientIdentifier, ClientName = spaApplication.ClientName, RedirectionUrls = spaApplication.RedirectionUris.Split(';') });
    }

    void AddMachineApplication(MachineApplication machineApplication)
    {
        dispatcher.Dispatch(new AddMachineClientApplicationAction { ClientId = machineApplication.ClientIdentifier, ClientName = machineApplication.ClientName, ClientSecret = machineApplication.ClientSecret });
    }

    void AddWebsiteApplication(WebsiteApplication websiteApplication)
    {
        dispatcher.Dispatch(new AddWebsiteApplicationAction { ClientId = websiteApplication.ClientIdentifier, ClientName = websiteApplication.ClientName, RedirectionUrls = websiteApplication.RedirectionUris.Split(';'), ClientSecret = websiteApplication.ClientSecret });
    }

    void AddSamlSpApplication(SamlSpApplication samlSpApplication)
    {
        dispatcher.Dispatch(new AddSamlSpApplicationAction { ClientIdentifier = samlSpApplication.ClientIdentifier, ClientName = samlSpApplication.ClientName, MetadataUrl = samlSpApplication.MetadataUrl, UseAcs = samlSpApplication.UseAcs });
    }

    void AddHighlySecuredWebsiteApplication(HighlySecuredWebApplication websiteApplication)
    {
        dispatcher.Dispatch(new AddHighlySecuredWebsiteApplicationAction { ClientId = websiteApplication.ClientIdentifier, ClientName = websiteApplication.ClientName, ClientSecret = websiteApplication.ClientSecret, IsDPoP = websiteApplication.ProofOfPossession == DpopName, RedirectionUrls = websiteApplication.RedirectionUris.Split(';'), SubjectName = websiteApplication.SubjectName });
    }

    void AddHighlySecuredWebsiteApplicationWithGrantMgtSupport(HighlySecuredWebApplicationWithGrantMgtSupport websiteApplication)
    {        
        dispatcher.Dispatch(new AddHighlySecuredWebsiteApplicationWithGrantMgtSupportAction { ClientId = websiteApplication.ClientIdentifier, ClientName = websiteApplication.ClientName, ClientSecret = websiteApplication.ClientSecret, IsDPoP = websiteApplication.ProofOfPossession == DpopName, RedirectionUrls = websiteApplication.RedirectionUris.Split(';'), SubjectName = websiteApplication.SubjectName, AuthDataTypes = websiteApplication.AuthDataTypes });
    }

    void AddMobileApplication(MobileApplication mobileApplication)
    {
        dispatcher.Dispatch(new AddMobileApplicationAction { ClientId = mobileApplication.ClientIdentifier, ClientName = mobileApplication.ClientName, RedirectionUrls = mobileApplication.RedirectionUris.Split(';') });
    }

    void AddWsFederationApplication(WsFederationApplication wsFederationApplication)
    {
        dispatcher.Dispatch(new AddWsFederationApplicationAction { ClientId = wsFederationApplication.ClientIdentifier, ClientName = wsFederationApplication.ClientName });
    }

    void AddExternalDeviceApplication(ExternalDeviceApplication deviceApplication)
    {
        dispatcher.Dispatch(new AddExternalDeviceApplicationAction { ClientId = deviceApplication.ClientIdentifier, ClientName = deviceApplication.ClientName, SubjectName = deviceApplication.SubjectName });
    }

    void AddDeviceApplication(DeviceApplication deviceApplication)
    {
        dispatcher.Dispatch(new AddDeviceApplicationAction { ClientId = deviceApplication.ClientIdentifier, ClientName = deviceApplication.ClientName, ClientSecret = deviceApplication.ClientSecret });
    }

    void AddCredentialIssuerApplication(CredentialIssuerApplication credentialIssuerApplication)
    {
        dispatcher.Dispatch(new AddCredentialIssuerApplicationAction { ClientId = credentialIssuerApplication.ClientIdentifier, ClientName = credentialIssuerApplication.ClientName, ClientSecret = credentialIssuerApplication.ClientSecret, RedirectionUrls = credentialIssuerApplication.RedirectionUris.Split(';') });
    }

    void AddWallet(Wallet wallet)
    {
        dispatcher.Dispatch(new AddWalletAction { ClientId = wallet.ClientId, ClientName = wallet.ClientName, ClientSecret = wallet.ClientSecret });
    }
}